package tech.aistar.day02;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 本类用来演示: application作用域
 *
 * @author: success
 * @date: 2021/4/16 1:35 下午
 */
@WebServlet(urlPatterns = "/day02/application")
public class ApplicationScopeController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1. 获取ServletContext对象
        ServletContext context = req.getServletContext();
        //2. 获取项目的上下文路径
        String contextPath = req.getContextPath();// /aistar
        //未来场景中 - 项目的上下文路径是需要放在application作用域中的
        context.setAttribute("path",contextPath);
    }
}
